<template>
  <view class="container relative">
    <!-- 使用视频组件 -->
    <videos
      ref="videosComponent"
      @change="handleVideoChange"
      @play="handleVideoPlay"
      @pause="handleVideoPause"
      @ended="handleVideoEnded"
      @error="handleVideoError"
    />

    <!-- 右侧操作按钮 - 使用view和image，并添加@tap事件代替@click -->
    <view class="right-buttons" style="position: fixed; right: 20rpx; bottom: 200rpx; z-index: 99999999999999">
      <!-- 发布视频按钮 -->
      <view class="button-item" @tap="handlePublishClick" v-if="state.config.is_video" style="z-index: 99999">
        <image src="/static/20250901230740.png" class="button-icon"></image>
        <text class="button-text">发布视频</text>
      </view>

      <!-- 直播列表按钮 -->
      <view class="button-item" @tap="handleLiveClick" style="z-index: 99999">
        <image src="/static/20250901230810.png" class="button-icon"></image>
        <text class="button-text">直播列表</text>
      </view>

      <!-- 开启直播按钮 -->
      <!--  -->
      <view class="button-item" @tap="handleStartLiveClick" style="z-index: 99999">
        <image src="/static/20250901230810.png" class="button-icon"></image>
        <text class="button-text">开启直播</text>
      </view>
    </view>
  </view>
</template>

<script>
  //import sheep from '@/sheep';
  // 正确导入Pinia的defineStore
  // import { defineStore } from 'pinia';
  // 导入视频组件
  import videos from '@/pages/yy/zujian/videos.vue';
  import sheep from '@/sheep';

  export default {
    components: {
      videos,
    },
    data() {
      return {
        // 移除视频相关数据，由组件内部管理
        state: {
          config: {
            is_video: false,
            is_live: false,
          },
        },
      };
    },
    onLoad() {
      livePower();
    },

    methods: {
      //livePower
      livePower() {
        sheep.$api.yy
          .livePower()
          .then((res) => {
            if (res.code === 1) {
              this.state.config = res.data;
            }
          })
          .catch((err) => {
            console.error('直播权限失败:', err);
          });
      },
      // 视频组件事件处理
      handleVideoChange(index) {
        // 处理视频切换事件
        console.log('视频切换到索引：', index);
      },
      handleVideoPlay(index) {
        // 处理视频播放事件
        console.log('视频开始播放，索引：', index);
      },
      handleVideoPause(index) {
        // 处理视频暂停事件
        console.log('视频暂停，索引：', index);
      },
      handleVideoEnded(index) {
        // 处理视频结束事件
        console.log('视频播放结束，索引：', index);
      },
      handleVideoError(index, error) {
        // 处理视频错误事件
        console.error('视频播放错误，索引：', index, error);
      },
      // 保留原有的导航方法
      handleStartLiveClick() {
        uni.navigateTo({
          url: '/pages/yy/liveStreaming',
        });
      },
      handleLiveClick() {
        console.log('1111111111==> ', 1111111111);
        uni.navigateTo({
          url: '/pages/yy/videoList',
        });
      },
      handlePublishClick() {
        uni.navigateTo({
          url: '/pages/yy/publishVideo',
        });
      },
    },
  };
</script>

<style lang="scss" scoped>
  .container {
    position: relative;
    width: 750rpx;
    height: 1334rpx;
    background-color: #000;
  }

  .relative {
    position: relative;
  }

  /* 右侧按钮样式 - 使用普通view和image */
  .right-buttons {
    display: flex;
    flex-direction: column;
    gap: 30rpx;
    background-color: rgba(0, 0, 0, 0.3);
    padding: 20rpx;
    border-radius: 20rpx;
  }

  .button-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10rpx;
    margin-top: 20rpx;
    padding: 10rpx;
  }

  .button-icon {
    width: 60rpx;
    height: 60rpx;
  }

  .button-text {
    font-size: 28rpx;
    color: #fdf27c;
    text-align: center;
    white-space: nowrap;
    margin-top: 20rpx;
  }
</style>
